package com.doit.day07

import org.apache.spark.sql.SparkSession

/**
 * @Author:
 * @WX: 17710299606
 * @Tips: 学大数据 ,到多易教育
 * @DOC: https://blog.csdn.net/qq_37933018?spm=1000.2115.3001.5343
 * @Description:
 */
object Demo01 {
  def main(args: Array[String]): Unit = {

        val session = SparkSession.builder()
              .appName("test")
              .master("local[*]")
              .getOrCreate()
            import  session.implicits._
            import org.apache.spark.sql.functions._

    val df = session.read.json("data/log")

   // df.printSchema()

 //   df.show(3)

    /**
     * select
     * event_name ,
     * count(1) as cnt
     * from
     * (
     * select
     * *
     * from
     * tb_log
     * where  from_unixtime(ts , 'yyyy-MM-dd') = '2024-04-01'
     * )t
     * group by  event_name
     */


    df.where("from_unixtime(ts/1000 , 'yyyy-MM-dd') = '2024-04-01'")
      .select("*")
      .groupBy("event_name")
      .count()
      .toDF("name" , "cnt")
      .where("cnt > 1")
      .select("name")
      .show()

    session.close()





  }

}
